<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/7/15
  Time: 9:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>活动报名</title>
<%--    引入样式表--%>
      <link rel="stylesheet" href="static/layui/css/layui.css">
<%--    引入js文件--%>
      <script src="static/layui/layui.js"></script>
  </head>
  <body>
  <img src="static/image/nb.png" width="200px" height="50px">
  <form id="addStudentForm" class="layui-form" action="student?method=addStudent" onsubmit="return dosubmit()" method="post">
    <div class="layui-form-item">
      <label class="layui-form-label">活动名称</label>
      <div class="layui-input-block">
        <input type="text" readonly="readonly"  value="${businessInfo.name}" required lay-verify="required"  autocomplete="off"
               class="layui-input">
      </div>
    </div>
    <input type="text" id="begin" hidden="hidden" value="${businessInfo.begin}">
    <input type="text" id="end" hidden="hidden" value="${businessInfo.end}">
    <input type="text" id="count"  hidden="hidden" value="${businessInfo.count}">
    <input type="text" id="doneApply" hidden="hidden"  value="${businessInfo.doneApply}">
    <input type="text" id="status"  hidden="hidden" value="${businessInfo.status}">
    <input type="text" name="business_id" hidden="hidden" value="${businessInfo.id}">
    <div class="layui-form-item">
      <label class="layui-form-label">人员姓名</label>
      <div class="layui-input-block">
        <input type="text" name="name" required lay-verify="required" placeholder="请输入人员姓名" autocomplete="off"
               class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">人员年龄</label>
      <div class="layui-input-block">
        <input type="text" name="age" required lay-verify="required|number" placeholder="请输入人员年龄" autocomplete="off"
               class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">学校/单位</label>
      <div class="layui-input-block">
        <input type="text" name="school" required lay-verify="required" placeholder="请输入人员学校" autocomplete="off"
               class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">手机号</label>
      <div class="layui-input-block">
        <input type="text" name="phone" required lay-verify="required|phone" placeholder="请输入手机号" autocomplete="off"
               class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-input-block">
        <button class="layui-btn" lay-submit lay-filter="saveStudentFilter">立即报名</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
      </div>
    </div>
  </form>
  </body>
  <script>
    layui.use(['jquery'], function(){
      var $ = layui.jquery;
      let status=$("#status").val();
      if(status!=0){
        alert("(*╹▽╹*)抱歉,活动已经下线!");
        window.location.href="error.html";
      }
      //判断报名人数是否已满
      let  count=$("#count").val();
      let  doneApply=$("#doneApply").val();

      if(doneApply>=count){
        alert("(*╹▽╹*)抱歉,名额已满!");
        window.location.href="error.html";
      }
      //判断活动是否开始
      var now =Date.parse(new Date());
      let  begin=Date.parse($("#begin").val());
      let  end=Date.parse($("#end").val());
      console.log(now+"||"+begin+"||"+end);
      if(now<begin){
        alert("(*╹▽╹*)抱歉,活动未开始!");
        window.location.href="error.html";
      }
      //判断活动是否结束
      if(now>end){
        alert("(*╹▽╹*)抱歉,活动已经结束!");
        window.location.href="error.html";
      }

    })

    //默认提交状态为false
    var commitStatus = false;
    function dosubmit(){

      if(commitStatus==false){
        //提交表单后，将提交状态改为true
        commitStatus = true;
        return true;
      }else{
        return false;
      }
    }
  </script>
</html>
